package com.wyman.context.support;

import com.wyman.BeanException;
import com.wyman.factory.support.DefaultListableBeanFactory;

/**
 * @Author 李伟民
 * @Description
 * @DateTime 2024/12/12 19:06
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext{

    private DefaultListableBeanFactory beanFactory;

    @Override
    public void refreshBeanFactory() throws BeanException {
        beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }


    private DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    public abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    public DefaultListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
